package cn.edu.jxust.controller.api.sysresource;

import cn.edu.jxust.common.domain.entity.Account;
import cn.edu.jxust.common.domain.web.api.sysresource.IMenuController;
import cn.edu.jxust.common.response.Result;
import cn.edu.jxust.common.response.ResultUtils;
import cn.edu.jxust.common.response.enums.ResultStatus;
import cn.edu.jxust.core.domain.repository.ResourceService;
import lombok.extern.slf4j.Slf4j;
import org.apache.shiro.SecurityUtils;
import org.springframework.web.bind.annotation.RestController;
import javax.annotation.Resource;

/**
 * <p>
 *  菜单相关前端控制器
 * </p>
 *
 * @author QiuKangming
 * @since 2020-06-29
 */
@Slf4j
@RestController
public class MenuController implements IMenuController {

    @Resource
    private ResourceService resourceService;

    @Override
    public Result getMenus(){

        try {
            //获取到当前用户的 roleId
            Integer roleId = ((Account) SecurityUtils.getSubject().getPrincipal()).getRoleId();
            return resourceService.getMenuTreeByRoleId(roleId);
        }catch (Exception e){
            log.error("[MenuController--getMenus] 异常: {}", e.getMessage());
            return ResultUtils.resultWithoutData(ResultStatus.FAILED);
        }

    }
}

